<?php

require_once('Twitter/Twitter.php');

class TwitterIntegrationPlugin extends SJB_PluginAbstract
{

	function pluginSettings()
	{
		return SJB_DB::query('SELECT * FROM `twitter`');
	}
	
	public static function twitterFeed($info = array())
    {
		return new SJB_Twitter($info);
	}
	
	public static function saveFeed($info) 
	{
		SJB_Twitter::saveFeed($info);
	}
	
	public static function getFeedInfoBySID($sid)
	{
		return SJB_Twitter::getFeedInfoBySID($sid);
	}
	
	public static function getAllFeeds()
	{
		return SJB_Twitter::getAllFeeds();
	}
	
	public static function deleteFeed($sid)
	{
		return SJB_Twitter::deleteFeed($sid);
	}

	/**
	 * @param $feedInfo
	 * @param Zend_Oauth_Token_Access $accessToken
	 * @return Zend_Service_Twitter
	 */
	public static function getZendServiceTwitter($feedInfo, Zend_Oauth_Token_Access $accessToken = null)
	{
		if (!$accessToken) {
			$accessToken = !empty($feedInfo['access_token']) ? unserialize($feedInfo['access_token']) : '';
		}

		return new Zend_Service_Twitter(
			array(
				'username' => $feedInfo['username'],
				'accessToken' => $accessToken,
				'oauthOptions' => array(
					'consumerKey' => $feedInfo['consumerKey'],
					'consumerSecret' => $feedInfo['consumerSecret'],
				)
			)
		);
	}
}
